home *** CD-ROM | disk | FTP | other *** search
-
- /*⌐ Copyright 1988-1991 UserLand Software, Inc. All Rights Reserved.*/
-
-
-
- #include "appletinternal.h"
- #include "ops.h"
- #include "kb.h"
-
-
-
- #define keycodeclear 71 /*keycodes for numeric keybad*/
- #define keycodeminus 78
- #define keycodeplus 69
- #define keycodetimes 67
- #define keycodeseven 89
- #define keycodeeight 91
- #define keycodenine 92
- #define keycodedivide 77
- #define keycodefour 86
- #define keycodefive 87
- #define keycodesix 88
- #define keycodecomma 72
- #define keycodeone 83
- #define keycodetwo 84
- #define keycodethree 85
- #define keycodeenter 76
- #define keycodezero 82
- #define keycodeperiod 65
-
-
- tykeystrokerecord keyboardstatus;
-
- static boolean flescapepending = false;
-
-
-
-
- boolean arrowkey (char chkb) {
-
- /*
- return true if the indicated key character is an arrow key.
- */
-
- register char ch = chkb;
-
- return (
- (ch == chuparrow) || (ch == chdownarrow) ||
-
- (ch == chleftarrow) || (ch == chrightarrow));
- } /*arrowkey*/
-
-
- tydirection keystroketodirection (char ch) {
-
- switch (ch) {
-
- case chleftarrow:
- return (left);
-
- case chrightarrow:
- return (right);
-
- case chuparrow:
- return (up);
-
- case chdownarrow:
- return (down);
- } /*switch*/
-
- return (nodirection);
- } /*keystroketodirection*/
-
-
- static void kbsetstatus (EventRecord ev, tykeystrokerecord *kbs) {
-
- /*
- 12/11/90 dmb: don't count the caps lock as a modifier in ctmodifiers.
-
- 2/21/91 dmb: handle calls for mousedown events. we just want to
- record modifier keys
- */
-
- register short ct;
- register char chkb;
- register short keycode;
- tykeystrokerecord kbcurrent;
-
- kbcurrent.flshiftkey = (ev.modifiers & shiftKey) != 0;
-
- kbcurrent.flcmdkey = (ev.modifiers & cmdKey) != 0;
-
- kbcurrent.floptionkey = (ev.modifiers & optionKey) != 0;
-
- kbcurrent.flalphalock = (ev.modifiers & alphaLock) != 0;
-
- kbcurrent.flcontrolkey = (ev.modifiers & controlKey) != 0;
-
- ct = 0;
-
- if (kbcurrent.flshiftkey) ct++;
-
- if (kbcurrent.flcmdkey) ct++;
-
- if (kbcurrent.floptionkey) ct++;
-
- /*
- if (kbcurrent.flalphalock) ct++;
- */
-
- if (kbcurrent.flcontrolkey) ct++;
-
- kbcurrent.ctmodifiers = ct;
-
- if (ev.what == mouseDown) {
-
- kbcurrent.chkb = chnul;
-
- kbcurrent.keycode = 0;
-
- kbcurrent.flautokey = false;
-
- kbcurrent.keydirection = nodirection;
- }
- else {
-
- kbcurrent.chkb = chkb = ev.message & charCodeMask; /*get the keystroke*/
-
- kbcurrent.flautokey = (ev.what == autoKey);
-
- kbcurrent.keycode = keycode = (ev.message & keyCodeMask) >> 8;
-
- kbcurrent.keydirection = keystroketodirection (chkb);
-
- if (kbcurrent.flcmdkey && kbcurrent.floptionkey) {
-
- /*
- we don't want to option character, so find the normal character from
- the keymap. see IM V-195
- */
-
- Handle hkchr;
- long state = 0;
-
- if (hkchr = GetResource ('KCHR', 0))
- kbcurrent.chkb = KeyTrans (*hkchr, kbcurrent.keycode, &state) & 0x000000ff;
- };
-
- kbcurrent.flkeypad = /*true if it is a keystroke from the numeric keypad*/
-
- (keycode == keycodeclear) || (keycode == keycodeminus) ||
-
- (keycode == keycodeplus) || (keycode == keycodetimes) ||
-
- (keycode == keycodeseven) || (keycode == keycodeeight) ||
-
- (keycode == keycodenine) || (keycode == keycodedivide) ||
-
- (keycode == keycodefour) || (keycode == keycodefive) ||
-
- (keycode == keycodesix) || (keycode == keycodecomma) ||
-
- (keycode == keycodeone) || (keycode == keycodetwo) ||
-
- (keycode == keycodethree) || (keycode == keycodeenter) ||
-
- (keycode == keycodezero) || (keycode == keycodeperiod);
- }
-
- *kbs = kbcurrent; /*set for caller*/
- } /*kbsetstatus*/
-
-
- setkeyboardstatus (EventRecord ev) {
-
- /*
- sets a global that may be referenced by anyone.
-
- should be called every time a new event is received.
- */
-
- kbsetstatus (ev, &keyboardstatus); /*use global*/
- } /*setkeyboardstatus*/
-
-
- keyboardclearescape (void) {
-
- flescapepending = false;
- } /*keyboardclearescape*/
-
-
- keyboardsetescape (void) {
-
- /*ouch (); /*audible feedback asap, multimedia!*/
-
- /*
- shellfrontrootwindowmessage ("\pCancelled.");
- */
-
- flescapepending = true;
- } /*keyboardsetescape*/
-
-
- boolean keyboardescape (void) {
-
- /*
- check to see if the user has pressed cmd-period. if not, no effect on
- the event queue and we return false.
-
- otherwise, we remove the keystroke and return true. the caller is expected
- to return quickly!
- */
-
- register unsigned long tc;
- tykeystrokerecord kbcurrent;
- EventRecord ev;
- static unsigned long lastcheck = 0;
-
- if (flescapepending)
- return (true);
-
- tc = TickCount ();
-
- if ((tc - 60) < lastcheck) /*check 1 time per second*/
- return (false);
-
- lastcheck = tc; /*remember for next time*/
-
- if (EventAvail (keyDownMask, &ev)) {
-
- kbsetstatus (ev, &kbcurrent);
-
- if (kbcurrent.flcmdkey && (kbcurrent.chkb == '.')) {
-
- GetNextEvent (keyDownMask, &ev); /*get rid of the cmd-period*/
-
- keyboardsetescape (); /*multimedia!*/
-
- return (true);
- }
- }
- else { /*potentially surrender the processor to background tasks*/
-
- /*WaitNextEvent (nullEvent, &ev, 1, nil);*/
- }
-
- /*motorsound ();*/
-
- return (false);
- } /*keyboardescape*/
-
-
- keyboardpeek (tykeystrokerecord *kbrecord) {
-
- register ptrkeystrokerecord p = kbrecord;
- KeyMap keys;
-
- clearbytes (p, longsizeof (tykeystrokerecord));
-
- GetKeys (&keys);
-
- (*p).flshiftkey = BitTst (&keys, 63);
-
- (*p).flcmdkey = BitTst (&keys, 48);
-
- (*p).floptionkey = BitTst (&keys, 61);
-
- (*p).flcontrolkey = BitTst (&keys, 60);
- } /*keyboardpeek*/
-
-
- static boolean keydown (short keycode) {
-
- KeyMap keys;
-
- GetKeys (&keys);
-
- return (BitTst (&keys, keycode));
- } /*keydown*/
-
-
- boolean enterkeydown (void) {
-
- return (keydown (75));
- } /*enterkeydown*/
-
-
- boolean optionkeydown (void) {
-
- return (keydown (61));
- } /*optionkeydown*/
-
-
- boolean cmdkeydown (void) {
-
- return (keydown (48));
- } /*cmdkeydown*/
-
-
- boolean shiftkeydown (void) {
-
- return (keydown (63));
- } /*shiftkeydown*/
-
-
-
-